using System;
using System.Collections.Generic;

namespace etcetera.Mvc.UI.Toolbar
{
    public class Toolbar : IToolbar
    {
        private ICollection<ToolbarItem> _items = new List<ToolbarItem>();

        public ICollection<ToolbarItem> Items { get { return _items; } }
        public IPagerToolStrip ToolStrip { get; set; }

        private string _refreshButtonTitle = "Refresh";

        public IToolbar AddButton(string linkTitle, string actionUrl, string buttonClass)
        {
            ToolbarButton button = new ToolbarButton(linkTitle, actionUrl, buttonClass);
            button.Toolbar = this;
            _items.Add(button);
            return this;
        }

        public IToolbar AddNavButton(NavButton navButton)
        {
            // TODO query parameter name for 'page'

            ToolbarNavButton button = new ToolbarNavButton(navButton);
            button.Toolbar = this;
            _items.Add(button);
            return this;
        }

        public IToolbar AddPageSizeSelect(params int[] options)
        {
            ToolbarSelect select = new ToolbarSelect(options);
            select.Toolbar = this;
            _items.Add(select);
            return this;
        }

        public IToolbar AddPageInput()
        {
            ToolbarPageInput pageInput = new ToolbarPageInput();
            pageInput.Toolbar = this;
            _items.Add(pageInput);
            return this;
        }

        public IToolbar AddPageStatus()
        {
            ToolbarPageStatus status = new ToolbarPageStatus();
            status.Toolbar = this;
            _items.Add(status);
            return this;
        }

        /// <summary>
        /// Adds a refresh button.
        /// </summary>
        /// <param name="reset">if set to <c>true</c> the refresh will point to the first page.</param>
        /// <returns></returns>
        public IToolbar AddRefreshButton(bool reset)
        {
            return AddRefreshButton(reset, _refreshButtonTitle);
        }

        /// <summary>
        /// Adds a refresh button.
        /// </summary>
        /// <param name="buttonTitle">The button title.</param>
        /// <returns></returns>
        public IToolbar AddRefreshButton(string buttonTitle)
        {
            return AddRefreshButton(false, buttonTitle);
        }

        /// <summary>
        /// Adds a refresh button.
        /// </summary>
        /// <param name="reset">if set to <c>true</c> the refresh will point to the first page.</param>
        /// <param name="buttonTitle">The button title.</param>
        /// <returns></returns>
        public IToolbar AddRefreshButton(bool reset, string buttonTitle)
        {
            ToolbarButton button = new ToolbarRefreshButton(reset, buttonTitle, "tBtnR");
            button.Toolbar = this;
            _items.Add(button);
            return this;
        }
    }
}